var pic = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202102%2F26%2F20210226073347_50f94.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1668131440&t=6df291a148cdb21289e91211d4daea32';
var vm = new Vue({
    el: "#app",
    data: {
        list: [
            { name: '秋刀鱼', price: 88, pic, count: 1 },
            { name: '大黄鱼', price: 777, pic, count: 2 },
            { name: '皮皮虾', price: 9, pic, count: 3 },
        ]
    },
    methods: {
        add(item) {
            item.count++;
        },
        sub(item) {
            if (item.count > 1) item.count--;
        },
        clean() {
            this.list = [];
        }
    },
    computed: {
        totalCount() {
            console.log('计算属性: totalCount 执行了');
            var sum = 0;
            this.list.forEach((item) => {
                sum += item.count;
            })
            console.log(sum);
            return sum;
        },
        totalPrice() {
            var sum = 0;
            this.list.forEach((item) => {
                sum += item.count * item.price;
            })
            return sum;
        }
    }
})